use std::process::exit;
use std::sync::Arc;
use spdlog::formatter::{pattern, PatternFormatter};
use spdlog::{info, LevelFilter};
use spdlog::sink::FileSink;
use redisoxy::{
    version, error::ProxyResult
};
use redisoxy::config::ConfigOption;
use redisoxy::error::ProxyError;
use redisoxy::log::init_log;
use redisoxy::option::ProxyOption;
use redisoxy::server::ProxyServer;


async fn run_main() -> ProxyResult<()> {

    let proxy_option = ProxyOption::default();
    let server = ProxyServer::new(proxy_option);
    server.start().await?;

    Ok(())
}

#[tokio::main]
async fn main() {
    // init log module
    let log_path = "access_main.log";
    if let Err(e) = init_log(log_path.to_string()) {
        eprintln!("{:?}", e);
        exit(0);
    }

    let config = match ConfigOption::parse_file(None) {
        Ok(c) => c,
        Err(e) => {
            println!("{:?}", e);
            return;
        }
    };

    info!("redisoxy version {} start", version::VERSION);

    let _ = run_main().await;
}
